<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <link type="text/css" rel="stylesheet" href="../styles/goods.css">
</head>
 <div id="good-frame"></div>
 
 <div class="goods">
 <!-- 
    名称
    产地
    价格
    库存
 -->
 <div class="good-box">
     <img src="../images/apple.jpg" class="good-img">
 </div>
 <div class="infor-box">
     <span class="good-name">苹果</span>
     <span class="good-loc">烟台</span>
     <span class="good-price">￥5</span>
 </div>
 <div class="add-good" onclick="addGood()">加入购物车</div>
</div>

<script type="text/javascript" src="../scripts/jquery.js"></script>
<script>
window.onload=function(){
	$.ajax({
		type:'POST',
		url:'serlvet/goodFrame',
		data:{
			"user":"john"
		},
		success:function(data,status){
			alert("成功！");
			if(data.size==0){}
			else{
				$("#good-frame").html("");
				 for(i=0;i<data.array.length;i++)
                 {
                     var goods=document.createElement('div');
                     goods.className="goods";
                     var goodBox=document.createElement('div');
                     goodBox.className="good-box";
                     var goodImg=document.createElement('img');
                     goodImg.className="good-img";
                     if(data.array[i].name=="苹果"){
                    	 goodImg.src="../images/apple.jpg";
                     }else if(data.array[i].name=="桃子"){
                    	 goodImg.src="../images/peach.jpg";
                     }else if(data.array[i].name=="梨"){
                    	 goodImg.src="../images/pear.jpg";
                     }else{
                    	 goodImg.src="../images/good.jpg";
                     }
					 goodBox.append(goodImg);
					 
                     	
                     var inforBox=document.createElement('div');
                     inforBox.className="infor-box";
                     var goodName=document.createElement('span');
                     goodName.className="good-name";
                     goodName.text(data.array[i].name);
                     var goodLoc=document.createElement('span');
                     goodLoc.className="good-loc";
                     goodLoc.text(data.array[i].brand);
                     var goodPrice=document.createElement('span');
                     goodPrice.className="good-price";
                     goodPrice.text("￥"+data.array[i].price);
                     inforBox.append(goodName);
                     inforBox.append(goodLoc);
                     inforBox.append(goodPrice);
                     
                     
                     var addGoodBtn=document.createElement('div');
                     addGoodBtn.className="add-good";
                     addGoodBtn.text("加入购物车");
                     addGoodBtn.onclick="addGood("+id+")";
                     
                     goods.append(goodBox);
                     goods.append(inforBox);
                     goods.append(addGoodBtn);
                     
                     $("#good-frame").append(goods);

                 }
                 
         	
			}
			
		},
		error:function(data,status){
			alert("失败");
		}
	})
}

function addGood(num){
	
}

</script>
</html>